package io.osw.modules.sys.controller;

import io.osw.common.utils.PageUtils;
import io.osw.common.utils.R;
import io.osw.common.validator.ValidatorUtils;
import io.osw.modules.sys.entity.TblConfEntity;
import io.osw.modules.sys.service.TblConfService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;



/**
 * 系统配置信息表
 *
 * @author guxiaoguang
 * @email xuebai864627555@gmail.com
 * @date 2019-01-07 20:54:02
 */
@RestController
@RequestMapping("sys/tblconf")
public class TblConfController extends AbstractController{
    @Autowired
    private TblConfService tblConfService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:tblconf:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tblConfService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:tblconf:info")
    public R info(@PathVariable("id") Long id){
        TblConfEntity tblConf = tblConfService.selectById(id);

        return R.ok().put("tblConf", tblConf);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:tblconf:save")
    public R save(@RequestBody TblConfEntity tblConf){
        tblConf.setCreateTime(new Date());
        tblConf.setCreateBy(getUserId());
        tblConf.setCompanyId(getUser().getCompanyId());
        tblConfService.insert(tblConf);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:tblconf:update")
    public R update(@RequestBody TblConfEntity tblConf){
        ValidatorUtils.validateEntity(tblConf);
        tblConf.setUpdateTime(new Date());
        tblConf.setUpdateBy(getUserId());
        tblConfService.updateAllColumnById(tblConf);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:tblconf:delete")
    public R delete(@RequestBody Long[] ids){
        tblConfService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
